package com.enjoy.springboot;

import java.io.FileReader;
import java.io.IOException;
import java.net.URL;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;

public class Util {


    public static String loadProperties(String key) {

        URL url = Util.class.getClassLoader().getResource("");
        String path = Objects.requireNonNull(url).getPath() + "application.properties";
        Properties properties = new Properties();
        try {
            properties.load(new FileReader(path));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
            if (entry.getKey().equals(key)) {
                return (String) entry.getValue();
            }
        }
        return null;
    }
}